<template>
<div>
    <!-- {{this.$store.state.secondCategory}} -->
    <el-card style="margin-top:20px;">
      <h3>品类管理</h3>
      <el-button @click="toCategoryAdd">添加品类</el-button>
      <p>当前商品分类ID：{{this.$store.state.secondCategory.id}}</p>
      <el-table :data="levaleTwoList" stripe style="width: 100%">
        <el-table-column prop="id" label="品类ID"></el-table-column>
        <el-table-column prop="name" label="品类名称"></el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button size="mini" @click="editName(scope.row)">修改名称</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
    <el-dialog title="收货地址" :visible.sync="dialogEditVisible">
      <el-form :model="editInfo">
        <el-form-item label="请输入新的品类名称">
        <el-input v-model="editInfo.id"></el-input>
      </el-form-item>
        <el-form-item label="请输入新的品类名称">
        <el-input v-model="editInfo.name"></el-input>
      </el-form-item>
        </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogEditVisible = false">取 消</el-button>
        <el-button type="primary" @click="editSure">确 定</el-button>
      </div>
    </el-dialog>
</div>
</template>

<script>
import { productType } from "../util/http";
import { categoryEdit } from "../util/http";
export default {
 // 组件名称
 name: 'demo',
 // 组件参数 接收来自父组件的数据
 props: [],
 components: {},
 data () {
 return {
    levaleTwoList: [],
    dialogEditVisible: false,
    editInfo: ""
}
 },
 computed: {},
 watch: {},
 methods: {
    async getSecondCategory(){
        const { data: res } = await productType(
        `/api/manage/category/get_category.do?categoryId=${this.$store.state.secondCategory.id}`
      );
      this.levaleTwoList = res.data;
    //   console.log(res)
    },
    editName(info) {
      this.dialogEditVisible = true;
      this.editInfo = info;
    },
    async editSure() {
      const {data:res} = await categoryEdit(`/api/manage/category/set_category_name.do?categoryId=${this.editInfo.id}&categoryName=${this.editInfo.name}`)
    //   console.log(res)
      if( res.status !== 0 ) this.$message.error("更新品类名字失败");
      this.getSecondCategory();
      this.dialogEditVisible = false;
      this.$message.success("更新品类名字成功");
    },
    toCategoryAdd(){
      this.$router.push('/categoryAdd')
    }
},
 beforeCreate () {
 },
 created () {
 },
 beforeMount () {
 },
 mounted () {
    this.getSecondCategory()
 },
}
</script> 
<style scoped>

</style>
